package org.jeeasy.system.modules.dict.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.dromara.autotable.annotation.mysql.MysqlTypeConstant;
import org.dromara.mpe.autotable.annotation.Column;
import org.dromara.mpe.autotable.annotation.Table;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.BaseEntity;
import org.jeeasy.common.core.enums.BooleanEnum;
import org.jeeasy.common.core.tools.Tools;

import java.io.Serial;
import java.util.Map;

/**
 * @author mobie
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@Table(value = "sys_table_dict", comment = "表类型字典")
public class SysTableDict extends BaseEntity<SysTableDict> {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 字典编码
     */
    @Column(comment = "字典编码", length = 32)
    private String dictCode;

    /**
     * 字典名称
     */
    @Column(comment = "字典名称", length = 32)
    private String dictName;

    /**
     * 查询表名
     */
    @Column(comment = "查询表名", length = 255)
    private String tableName;

    /**
     * 数据源名称
     */
    @Column(comment = "数据源名称", length = 32)
    private String databaseName;

    /**
     * 值字段
     */
    @Column(comment = "值字段", length = 64)
    private String valueColumn;

    /**
     * 名称字段
     */
    @Column(comment = "名称字段", length = 64)
    private String nameColumn;

    /**
     * 是否为树表
     */
    @Column(comment = "是否为树表", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer isTree;

    /**
     * 父级字段名称
     */
    @Column(comment = "父级字段名称", length = 24)
    private String parentId;

    /**
     * 叶子节点
     */
    @Column(comment = "叶子节点字段名称", length = 64)
    private String leafColumn;

    /**
     * 父级字段名称
     */
    @Column(comment = "父级字段名称", length = 32)
    @JsonIgnore
    private String parentValue;

    /**
     * 启用标记 0: 未启用 1： 启用
     */
    @Column(comment = "启用标记", length = 1, type = MysqlTypeConstant.TINYINT)
    //@Dict(dictEnum = EnableFlagEnum.class)
    private Integer enableFlag;

    public void replaceParams(Map<String, Object> params) {
        if (Tools.isNotEmpty(this.tableName)) {
            this.tableName = Tools.replaceParams(this.tableName, params);
        }
    }
}